﻿Imports System.Collections.Generic
Imports System.Data
Imports CondorTravel.BC
Imports CondorTravel.BE
Imports CondorTravelUTIL.DL

Public Class BuscarServicios
    Inherits PaginaBase
    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarServicios()
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub

    Private Sub ListarServicios()
        Dim objServiciosBE As New ServicioBE
        Dim objUtil As New Funciones
        objServiciosBE.CodServicio = 0
        objServiciosBE.NombreServicio = ""
        objServiciosBE.FechaInicio = ""
        objServiciosBE.FechaFin = ""
        objServiciosBE.CodProveedor = 0
        objServiciosBE.Estado = ""
        objServiciosBE.codPais = 0
        objServiciosBE.codCiudad = 0
        objServiciosBE.Tarifa = 0

        If IsNumeric(txtCodServ.Text.Trim) Then
            objServiciosBE.CodServicio = Val(objUtil.ReemplazarTexto(txtCodServ.Text.Trim))
        Else
            objServiciosBE.CodServicio = 0
        End If
        If txtNomServ.Text.Trim <> "" Then
            objServiciosBE.NombreServicio = objUtil.ReemplazarTexto(txtNomServ.Text.Trim)
        Else
            objServiciosBE.NombreServicio = ""
        End If
        Dim objServicio As New ServicioBC
        dtgServicio.DataSource = objServicio.ListarServicioBusq(objServiciosBE)
        dtgServicio.DataBind()
        If dtgServicio.Rows.Count <= 0 Then
            dtgServicio.Visible = False
            lblError.Visible = True
        Else
            dtgServicio.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click
        Dim dt As New DataTable
        Dim scodigoServicio As String = String.Empty
        Dim sNombreServicio As String = String.Empty
        Dim scadena As String



        Dim iContador As Integer
        For Each Me.itemgridview In dtgServicio.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")
            If casilla.Checked = True Then
                iContador = iContador + 1
            End If
        Next

        If iContador > 1 Then
            Alerta("Solo se permite seleccionar un registro.", False, String.Empty)
            Exit Sub
        End If


        For Each Me.itemgridview In dtgServicio.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                scodigoServicio = CType(itemgridview.FindControl("lblcodigoServ"), Label).Text
                sNombreServicio = CType(itemgridview.FindControl("lblNombreServ"), Label).Text

            End If

        Next

        If scodigoServicio = String.Empty Then
            Exit Sub
        End If

        scadena = scodigoServicio
        Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BSCodigoServicio") = scodigoServicio
        Session("BSNombreServicio") = sNombreServicio

    End Sub
End Class